#!/usr/bin/env python3
"""
添加placeholder字段到work_order_fields表
"""

import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from backend.wsgi import create_app
import sqlite3

def add_placeholder_field():
    """添加placeholder字段到work_order_fields表"""
    db_path = '/home/gd/dispatch-system/backend/instance/dispatch_system.db'
    
    try:
        # 使用直接的SQLite连接
        conn = sqlite3.connect(db_path)
        cursor = conn.cursor()
        
        # 检查字段是否已存在
        cursor.execute("PRAGMA table_info(work_order_fields)")
        columns = [row[1] for row in cursor.fetchall()]
        
        if 'placeholder' not in columns:
            print("添加placeholder字段到work_order_fields表...")
            cursor.execute(
                "ALTER TABLE work_order_fields ADD COLUMN placeholder VARCHAR(200)"
            )
            conn.commit()
            print("placeholder字段添加成功")
        else:
            print("placeholder字段已存在，跳过添加")
            
        conn.close()
        
    except Exception as e:
        print(f"添加placeholder字段失败: {e}")
        raise

if __name__ == '__main__':
    add_placeholder_field()
    print("迁移完成")